//
//  CXHAppDelegate.m
//  CXHAdSDK-TopOn
//
//  Created by 二跳 on 10/10/2024.
//  Copyright (c) 2024 二跳. All rights reserved.
//

#import "CXHAppDelegate.h"
#import <AnyThinkSDK/AnyThinkSDK.h>

@interface CXHAppDelegate () <ATSplashDelegate>

@end

@implementation CXHAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    //开启日志
    [ATAPI setLogEnabled:YES];//Turn on debug logs
    //开启日志后，调用检查集成情况方法
    [ATAPI integrationChecking];
    // 直接初始化SDK
    [[ATAPI sharedInstance] startWithAppID:@"a67079eb93fa8f" appKey:@"a39fc3d1d2b502fc94b3b4c705e7aea73" error:nil];
        //....
    // Override point for customization after application launch.

//    [self loadSplashAd];
    return YES;
}

- (void)loadSplashAd{
    
    NSLog(@"======加载开屏广告");
    NSDictionary *extra = @{
        kATSplashExtraTolerateTimeoutKey : @5.5,   // 开屏广告加载超时时间
        kATAdLoadingExtraMediaExtraKey:@"custom_values",
    };

    // 固价：b68b94aeb673f0
    // 头部竞价：b68b94c555cc49
    [[ATAdManager sharedManager] loadADWithPlacementID:@"b68b94c555cc49" extra:extra delegate:self containerView:nil];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [[ATAdManager sharedManager] showSplashWithPlacementID:@"b68b94c555cc49" config:[ATShowConfig new] window:self.window inViewController:self.window.rootViewController extra:nil delegate:self];
    });
}

/// Ad bidding success
- (void)didFinishBiddingADSourceWithPlacementID:(NSString *)placementID
                                          extra:(NSDictionary*)extra{
    
}

/// Ad bidding fail
- (void)didFailBiddingADSourceWithPlacementID:(NSString*)placementID
                                        extra:(NSDictionary*)extra
                                        error:(NSError*)error{
    NSLog(@"====开屏广告bid失败:%@", error);
}

/// Callback when the successful loading of the ad
- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID{
    NSLog(@"====开屏广告加载成功");
}



/// Callback of ad loading failure
- (void)didFailToLoadADWithPlacementID:(NSString*)placementID
                                 error:(NSError*)error{
    NSLog(@"====开屏广告加载失败:%@", error);
}


/// Splash ad displayed successfully
- (void)splashDidShowForPlacementID:(NSString *)placementID
                              extra:(NSDictionary *)extra{
    
}

/// Splash ad click
- (void)splashDidClickForPlacementID:(NSString *)placementID
                               extra:(NSDictionary *)extra{
    
}

/// Splash ad closed
- (void)splashDidCloseForPlacementID:(NSString *)placementID
                               extra:(NSDictionary *)extra{
    
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}



- (void)didFinishLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra { 
    
}


- (void)didRevenueForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra { 
    
}


- (void)didStartBiddingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra { 
    
}


- (void)didStartLoadingADSourceWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra { 
    
}


@end
